package com.dede.test

import android.Manifest
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Toast
import com.dede.mypermission.MyPermission

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun click(v: View) {
        MyPermission.with(this)
                .requestCode(100)
                .onGranted {
                    toast("权限允许 ${it.permission} 读取sd卡 ${it.isShouldShowRequestPermissionRationale}")
                }
                .onDenied {
                    toast("权限拒绝 ${it.permission} 读取sd卡 ${it.isShouldShowRequestPermissionRationale}")
                }
                .permission(Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .request()
    }

    private fun toast(msg: String) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
    }
}
